package com.sikaryofficial.workbench.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sikaryofficial.common.core.domain.R;
import com.sikaryofficial.common.core.utils.PageUtil;
import com.sikaryofficial.common.core.web.domain.PageResult;
import com.sikaryofficial.workbench.domain.dto.req.membership.MembershipListReq;
import com.sikaryofficial.workbench.domain.dto.req.membership.MembershipPolicySaveReq;
import com.sikaryofficial.workbench.domain.dto.req.membership.MembershipUpdateStatusReq;
import com.sikaryofficial.workbench.domain.dto.resp.membership.MembershipPolicyDTO;
import com.sikaryofficial.workbench.domain.entity.MembershipPolicyLog;
import com.sikaryofficial.workbench.manager.MembershipPolicyManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author : wuweihong
 * @desc : 会员激励政策接口定义
 * @date : 2024-10-20
 */

@RestController
@RequestMapping("/membership")
@Valid
@Api(tags = "运营-会员激励模块")
@Slf4j
public class MembershipPolicyController {

	@Autowired
	private MembershipPolicyManager membershipPolicyManager;

	@PostMapping("/listPage")
	@ApiOperation("激励政策分页列表")
	public PageResult<MembershipPolicyDTO> listMembershipPage(@RequestBody MembershipListReq listReq) {
		IPage<MembershipPolicyDTO> page = membershipPolicyManager.listMembershipPage(listReq);
		return PageUtil.success(page.getRecords(), page.getTotal());
	}

	@GetMapping("/{membershipPolicyId}")
	@ApiOperation("获取详情")
	public R<MembershipPolicyDTO> getDetail(@PathVariable("membershipPolicyId") Long membershipPolicyId) {
		return R.ok(membershipPolicyManager.getDetail(membershipPolicyId));
	}

	@PostMapping("/saveMembership")
	@ApiOperation("创建或更新会员激励政策")
	public R<Long> saveMembershipPolicy(@Validated @RequestBody MembershipPolicySaveReq saveReq) {
		return R.ok(membershipPolicyManager.saveMembershipPolicy(saveReq));
	}

	@PostMapping("/updateBatchStatus")
	@ApiOperation("批量更新会员激励政策状态")
	public R<Boolean> updateBatchStatus(@RequestBody MembershipUpdateStatusReq updateStatusReq) {
		return R.ok(membershipPolicyManager.updateBatchStatus(updateStatusReq));
	}

	@PostMapping("/delete")
	@ApiOperation("批量删除")
	public R<Boolean> deleteMembershipPolicy(@RequestBody List<Long> membershipPolicyIds) {
		return R.ok(membershipPolicyManager.deleteBatch(membershipPolicyIds));
	}

	@GetMapping("/logInfo/{membershipPolicyId}")
	@ApiOperation("日志查询")
	public R<List<MembershipPolicyLog>> getLogInfoList(@PathVariable Long membershipPolicyId) {
		return R.ok(membershipPolicyManager.getLogList(membershipPolicyId));
	}

}
